获得窗口>原点坐标<失败的问题

来源:百度知道 编辑:UC知道 时间:2024/05/07 15:55:54
我用Delphi编写个程序的时候,获取窗口原点坐标的时候用到了
GetWindowOrgEx
但是不知道这个函数到底该怎么用
函数功能:该函数为指定的设备环境获取窗口原点的X坐标和Y坐标。
这里有它的说明
函数原型:BOOL GetWindowOrgEx(HDC hdc, LPPOINT lpPoint);

参数:

hdc:指向设备环境的句柄。

lpPoint:指向POINT结构的指针,该结构以页面为单位存放窗口原点的坐标。

返回值:如果函数调用成功,返回值为非零值,否则为零。

速查:Windows NT:3.1及以上版本;Windows:95及以上版本;Windows CE:不支持;头文件:wingdi.h;库文件:gdi32.lib。

我的源代码在这里
unit Unit10;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
MyHwnd: Hwnd;
h:THandle;
p

没好好看题目就回答了。

你的调用是没有错的。0.0没错啊,因为你是从你的form的Handle取得的HDC啊。

你要是想取坐标:

procedure TForm1.Button1Click(Sender: TObject);
var
p:TPoint;
begin
p.X := self.Left;
p.Y := self.Top;
p := ClientToScreen(p);
label1.Caption := IntToStr(p.X);
label2.Caption := IntToStr(p.Y);
end;